package com.you.atlas.web.place.module.action;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.dataresolver.FormGroup;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.you.atlas.biz.place.service.SmallNoteService;
import com.you.common.webx.AuthContext;
import com.you.place.dal.dao.dataobject.SmallNoteDO;

public class SmallNoteAction {

    @Autowired
    private SmallNoteService smallNoteService;

    public void doAdd(@FormGroup("postSmallNote") SmallNoteDO smallNoteDO, @Param("placeId") Long placeId,
                      Navigator navigator) {
        if (placeId == null) {
            navigator.redirectTo("placeModule").withTarget("error.vm");
            return;
        }
        if(!AuthContext.getContext().isLogin()){
            navigator.redirectTo("placeModule").withTarget("error.vm");
            return;
        }
        smallNoteDO.setPlaceId(placeId);
        smallNoteDO.setMemberId(AuthContext.getContext().getMemberId());
        smallNoteDO.setPlaceId(placeId);
        if (smallNoteService.addNote(smallNoteDO)) {
            navigator.redirectTo("placeModule").withTarget("placeView.vm").withParameter("id", placeId.toString());
        }
    }
}
